﻿using NetFrameworkExtensions;
using NetFrameworkExtensions.Utils;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Text;
using System.Collections.Generic;
using System.Collections;
using System.IO;

namespace NetFrameworkExtensions.Test.Utils
{
  [TestClass()]
  public class TextFilterTests
  {
    [TestMethod]
    public void TextFilterTest1()
    {
      var textFilter = new TextFilter();
      textFilter.TermPattern = @"[\w\d]+";
      textFilter.Filter = "Hello World!!!";

      var input1 = new string[]
      {
        null,
        "",
        "abc",
        "hello",
        "world",
        "!!!",
        "helloworld",
        "abchelloworldxyz",
        "abchello worldxyz",
        "abchelloworldxyz!!!",
        "abchello worldxyz!!!",
        "hello world!!!",
        "HELLO WORLD!!!",
        "HËlLÓ WÖRlD!!!",
      };
      var accept1 = new bool[]
      {
        false, //null,
        false, //"",
        false, //"abc",
        false, //"hello",
        false, //"world",
        false, //"!!!",
        true , //"helloworld",
        true , //"abchelloworldxyz",
        true , //"abchello worldxyz",
        true , //"abchelloworldxyz!!!",
        true , //"abchello worldxyz!!!",
        true , //"hello world!!!",
        true , //"HELLO WORLD!!!",
        true , //"HËlLÓ WÖRlD!!!",
      };

      for (int i = 0; i < input1.Length; i++)
      {
        Assert.AreEqual(accept1[i], textFilter.Accept(input1[i]));
      }
    }
    [TestMethod]
    public void TextFilterTest2()
    {
      var textFilter = new TextFilter();
      textFilter.TermPattern = @"[\w\d]+";
      textFilter.Filter = "Hello World!!!";

      var input1 = new string[][]
      {
        null,
        new string[] { "" },
        new string[] { "abc" },
        new string[] { "hello" },
        new string[] { null, "world" },
        new string[] { "!!!", null },
        new string[] { "hello", "world" },
        new string[] { "abchello", null, "worldxyz" },
        new string[] { "abc", null, "hello wor", "ldxyz" },
        new string[] { "abchello", "worldxyz!!!" },
        new string[] { "abchello", " worldxyz!!!" },
        new string[] { "hello", "world!!!" },
        new string[] { "HELLO WORLD", "!!!" },
        new string[] { "HËlLÓ ", "!!!", "", null, "WÖRlD" },
      };
      var accept1 = new bool[]
      {
        false, //null,
        false, //new string[] { "" },
        false, //new string[] { "abc" },
        false, //new string[] { "hello" },
        false, //new string[] { null, "world" },
        false, //new string[] { "!!!", null },
        true , //new string[] { "hello", "world" },
        true , //new string[] { "abchello", null, "worldxyz" },
        false, //new string[] { "abc", null, "hello wor", "ldxyz" },
        true , //new string[] { "abchello", "worldxyz!!!" },
        true , //new string[] { "abchello", " worldxyz!!!" },
        true , //new string[] { "hello", "world!!!" },
        true , //new string[] { "HELLO WORLD", "!!!" },
        true , //new string[] { "HËlLÓ ", "!!!", "", null, "WÖRlD" },
      };

      for (int i = 0; i < input1.Length; i++)
      {
        Assert.AreEqual(accept1[i], textFilter.Accept(input1[i]), input1[i] == null ? "null" : input1[i].ToStringList());
        Assert.AreEqual(accept1[i], textFilter.Accept((IEnumerable<string>)input1[i]), input1[i] == null ? "null" : input1[i].ToStringList());
      }
    }
  }
}
